package j06array;

import java.util.ArrayList;
import java.util.List;

class Man{
    String name;
    int age;

    public Man(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public int compareAge(Man man){
        return age - man.age;
    }

    @Override
    public String toString() {
        return "Man{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class J4sort {
    public static void main(String[] args) {
        List<Man> l1 = new ArrayList<>();
        l1.add(new Man("jack",12));
        l1.add(new Man("luct",55));
        l1.add(new Man("abc",2));
        l1.add(new Man("xy",7));
        //小-大
//        l1.sort((m1,m2)->m1.age- m2.age);

//        l1.sort((m1,m2)->m2.age- m1.age);
//        l1.sort((m1,m2)->m1.name.compareTo(m2.name));

        l1.sort((m1,m2)->m1.compareAge(m2));
        System.out.println("l1 = " + l1);
    }


}
